<style>
    .amily2-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px;
        width: 100%;
    }
    .header-column {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    .header-column.center {
        gap: 0px;
    }
    .side-button {
        writing-mode: vertical-rl; /* 【V59.0】恢复垂直模式 */
        text-orientation: mixed;
        height: 140px;
        width: 50px;
        padding: 10px 5px;
        text-align: center;
        line-height: 1.3;
    }
    .side-button > i {
        writing-mode: horizontal-tb;
        display: block;
        margin: 0 auto 10px auto;
        font-size: 1.3em;
    }
    #amily2_open_tutorial, #amily2_update_button_new {
        writing-mode: horizontal-tb !important;
        height: auto !important;
        width: auto !important;
        padding: 5px 10px !important;
        line-height: normal !important;
    }
    #amily2_update_button_new {
        display: none;
        background-color: #4CAF50 !important;
    }
    
    .version-info-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        background-color: rgba(255, 255, 255, 0.03);
        border-radius: 5px;
        font-size: 12px;
        line-height: 1.3;
    }
    
    .version-info-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        color: #adb6e6;
    }
    
    .version-label {
        font-size: 10px;
        opacity: 0.7;
        margin-bottom: 2px;
    }
    
    .version-number {
        font-weight: bold;
        font-family: monospace;
    }
    
    .version-current .version-number {
        color: #68b7ff;
    }
    
    .version-latest .version-number {
        color: #4CAF50;
    }
    
    .version-latest.has-update .version-number {
        color: #ff6b6b;
        animation: glow 2s ease-in-out infinite alternate;
    }
    
    @keyframes glow {
        from { text-shadow: 0 0 5px rgba(255, 107, 107, 0.5); }
        to { text-shadow: 0 0 10px rgba(255, 107, 107, 0.8), 0 0 15px rgba(255, 107, 107, 0.3); }
    }
</style>
<div class="flex-container">
    <div id="amily2_chat_optimiser">

        <div id="auth_panel" style="display: none;">
            <div class="auth-header">
                <div class="auth-title"><i class="fas fa-crown"></i> Amily2号优化助手 - 授权验证</div>
                <div class="auth-subtitle">解锁完整功能 享受智能优化体验</div>
                <div id="expiry_info"></div>
            </div>
            <div class="auth-code-input">
                <input type="password" id="amily2_auth_code" placeholder="输入授权码..."><button id="auth_submit">验证</button>
            </div>
            <div class="auth-daily-code">
                <span>今日授权码:</span>
                <span id="amily2_daily_code_display" class="daily-code">正在生成...</span>
                <button id="amily2_copy_daily_code" class="copy-button" title="复制授权码"><i class="fas fa-copy"></i></button>
            </div>
            <div class="auth-footer">声明:完全免费，禁止商用。仅供娱乐，严禁用于任何违法行为,且任何使用行为与作者无关。</div>
        </div>


<div class="plugin-features" style="display: none;">

<fieldset class="settings-group">
    <legend><i class="fas fa-cog"></i> Amily中枢</legend>
    <div class="amily2-header">
        <div class="header-column center" style="width: 100%; flex-direction: row; justify-content: center; gap: 20px;">
            <div class="main-toggle amily2_settings_block" style="margin: 0;">
                <label class="toggle-switch">
                    <input id="amily2_enabled" type="checkbox" />
                    <span class="slider"></span>
                </label>
            </div>
            <button id="amily2_open_tutorial" class="menu_button small_button interactable" title="查看使用教程">
                教程
            </button>
        </div>
    </div>
</fieldset>

<fieldset class="settings-group">
    <legend><i class="fas fa-plus-circle"></i> 新增扩展</legend>
    <div class="button-group" style="display: flex; justify-content: space-between; gap: 8px;">
        <button id="amily2_open_additional_features" class="menu_button wide_button"><i class="fas fa-landmark-dome"></i> 内阁密室</button>
        <button id="amily2_open_rag_palace" class="menu_button wide_button"><i class="fas fa-brain"></i> 翰林学院</button>
        <button id="amily2_open_memorisation_forms" class="menu_button wide_button"><i class="fas fa-table"></i> 内存储司</button>
        <button id="amily2_open_plot_optimization" class="menu_button wide_button"><i class="fas fa-feather-alt"></i> 剧情优化</button>
        <button id="amily2_open_character_world_book" class="menu_button wide_button"><i class="fa-solid fa-book-atlas"></i> 角色世界</button>
    </div>
</fieldset>
 
<fieldset class="settings-group">
    <legend><i class="fas fa-bullhorn"></i> 作者留言</legend>
    <div id="amily2_message_board" style="display: flex; justify-content: center; align-items: center; padding: 8px; background-color: rgba(255, 255, 255, 0.05); border-radius: 5px; min-height: 40px;">
        <div id="amily2_message_content" style="color: #adb6e6; font-size: 13px; line-height: 1.5; text-align: center;"></div>
    </div>
</fieldset>

<fieldset class="settings-group">
    <legend><i class="fas fa-code-branch"></i> 版本信息</legend>
    <div class="version-info-container">
        <div class="version-info-item version-current">
            <div class="version-label">当前版本</div>
            <div id="amily2_current_version" class="version-number">加载中...</div>
        </div>
        <div class="version-info-item version-center" style="display: flex; flex-direction: column; align-items: center; gap: 5px;">
            <div style="position: relative;">
                <button id="amily2_update_button" class="menu_button small_button interactable" title="查看更新日志">
                    <i class="fas fa-bell"></i>
                </button>
                <div id="amily2_update_indicator" class="update-indicator" style="display: none;"></div>
            </div>
            <button id="amily2_update_button_new" class="menu_button small_button interactable" title="查看更新日志">更新</button>
        </div>
        <div class="version-info-item version-latest">
            <div class="version-label">最新版本</div>
            <div id="amily2_latest_version" class="version-number">检查中...</div>
        </div>
    </div>
</fieldset>

<hr class="header-divider">

            <fieldset class="settings-group">
                <legend><i class="fas fa-cogs"></i> 正文优化</legend>


                <div class="control-pair-container" style="justify-content: space-around;">
                    <div class="amily2_settings_block">
                        <label for="amily2_optimization_enabled">启动优化</label>
                        <label class="toggle-switch">
                            <input id="amily2_optimization_enabled" type="checkbox" />
                            <span class="slider"></span>
                        </label>
                        <small class="notes">正文优化功能开关</small>
                    </div>
                    <div class="amily2_settings_block">
                        <label for="amily2_optimization_exclusion_enabled">内容排除</label>
                        <label class="toggle-switch">
                            <input id="amily2_optimization_exclusion_enabled" type="checkbox" />
                            <span class="slider"></span>
                        </label>
                        <small class="notes">正文优化排除开关</small>
                    </div>
                    <div class="amily2_settings_block">
                        <label for="amily2_greeting_optimization_enabled">暂未完成</label>
                        <label class="toggle-switch">
                            <input id="amily2_greeting_optimization_enabled" type="checkbox" disabled />
                            <span class="slider"></span>
                        </label>
                        <small class="notes">当前功能正在重构</small>
                    </div>
                </div>

                <hr style="border-style: dashed; margin: 10px 0;">

                <div class="amily2_settings_block">
                    <label for="amily2_optimization_target_tag">御定优化标签</label>
                    <input id="amily2_optimization_target_tag" type="text" class="text_pole" placeholder="例如: content, 正文" />
                    <small class="notes">指定Amily2号精准优化的唯一XML标签名。若留空或未找到，则不执行优化。</small>
                </div>


                <div class="amily2_settings_block">
                    <input id="amily2_show_optimization_toast" type="checkbox">
                    <label for="amily2_show_optimization_toast">显示优化通知</label>
                    <small class="notes">启用后，将在优化完成后弹出通知。</small>
                </div>

                <div class="amily2_settings_block">
                    <label>优化模式选择:</label>
                    <div class="radio-toggle-group">
                        <input type="radio" id="amily2_mode_intercept" name="amily2_optimization_mode" value="intercept" checked>
                        <label for="amily2_mode_intercept">无感优化</label>
                        <input type="radio" id="amily2_mode_refresh" name="amily2_optimization_mode" value="refresh">
                        <label for="amily2_mode_refresh">刷新优化</label>
                    </div>
                    <small class="notes">无感优化：直接替换文本，速度更快但要关流式，高楼层推荐。刷新优化：重载聊天界面，更加稳定无需关流式，低楼层推荐。</small>
                </div>
            </fieldset>

            <fieldset class="settings-group">
                <legend><i class="fas fa-network-wired"></i> API与模型配置</legend>
                <div class="amily2_settings_block">
                    <label for="amily2_api_provider">API 提供商</label>
                    <select id="amily2_api_provider" class="text_pole">
                        <option value="openai">OpenAI 自定义兼容</option>
                        <option value="openai_test">实验性全兼容</option>
                        <option value="google">Google 直连</option>
                        <option value="sillytavern_backend">SillyTavern 后端</option>
                        <option value="sillytavern_preset">SillyTavern 预设</option>
                    </select>
                </div>
                
                <!-- OpenAI兼容：需要API URL和API Key -->
                <div class="amily2_settings_block" id="amily2_api_url_wrapper">
                    <label for="amily2_api_url">API URL</label>
                    <input id="amily2_api_url" type="text" class="text_pole" placeholder="http://localhost:3000/v1" />
                </div>
                
                <!-- API Key字段（OpenAI兼容和Google直连需要） -->
                <div class="amily2_settings_block" id="amily2_api_key_wrapper">
                    <label for="amily2_api_key">API Key</label>
                    <input id="amily2_api_key" type="password" class="text_pole" placeholder="sk-..." />
                </div>
                
                <!-- SillyTavern预设选择器 -->
                <div class="amily2_settings_block" id="amily2_preset_wrapper" style="display: none;">
                    <label for="amily2_preset_selector">选择预设</label>
                    <select id="amily2_preset_selector" class="text_pole">
                        <option value="">请选择预设...</option>
                    </select>
                </div>

<div class="amily2_settings_block">
    <label for="amily2_model_selector">模型</label>
    <div class="flex-container" id="amily2_model_selector">

        <div id="amily2_model_autofetch_wrapper" style="display: flex; flex: 1; gap: 5px;">
            <select id="amily2_model" class="text_pole" style="flex: 1;"></select>
            <button id="amily2_refresh_models" class="menu_button interactable"><i class="fas fa-sync-alt"></i> 刷新</button>
        </div>

        <input id="amily2_manual_model_input" type="text" class="text_pole" style="flex: 1; display: none;" placeholder="请在此手动输入并保存模型ID"/>
    </div>
    <div id="amily2_model_notes" class="notes"></div>
</div>


                <div class="amily2_settings_block">
                    <label for="amily2_max_tokens">最大Token数: <span id="amily2_max_tokens_value"></span></label>
                    <input id="amily2_max_tokens" type="range" min="100" max="100000" step="50" />
                </div>
                <div class="amily2_settings_block">
                    <label for="amily2_temperature">思考活跃度: <span id="amily2_temperature_value"></span></label>
                    <input id="amily2_temperature" type="range" min="0" max="2" step="0.1" />
                </div>
                <div class="amily2_settings_block">
                    <label for="amily2_context_messages">上下文参考数: <span id="amily2_context_messages_value"></span></label>
                    <input id="amily2_context_messages" type="range" min="0" max="10" step="1" />
                </div>
            </fieldset>

            <fieldset class="settings-group">
                <legend><i class="fas fa-edit"></i> 统一提示词编辑器</legend>


                <div class="amily2_settings_block">
                    <div class="label-with-button">
                        <label for="amily2_prompt_selector">选择要编辑的设定:</label>
                        <i id="amily2_expand_editor" class="editor_maximize fa-solid fa-maximize right_menu_button interactable" title="展开编辑器" tabindex="0"></i>
                    </div>
                    <select id="amily2_prompt_selector" class="text_pole">
                        <option value="mainPrompt">破限提示词 (最高优先级)</option>
                        <option value="systemPrompt">预设提示词（任务规则）</option>
                        <option value="outputFormatPrompt">格式提示词 </option>
                    </select>
                </div>

                <div class="amily2_settings_block prompt-editor-area">
                    <textarea id="amily2_unified_editor" class="text_pole" rows="4"></textarea>
                    <div class="editor-buttons-panel">
                        <button id="amily2_unified_save_button" class="menu_button accent small_button interactable"><i class="fas fa-save"></i> 保存当前</button>
                        <button id="amily2_unified_restore_button" class="menu_button secondary small_button interactable"><i class="fas fa-undo"></i> 恢复默认</button>
                    </div>
                </div>
            </fieldset>

<fieldset class="settings-group">

    <legend><i class="fas fa-book-open"></i> 世界书档案司与律法</legend>

    <div class="amily2_lore_config_wrapper">

        <div class="amily2_lore_config_section">
            <div class="amily2_settings_block">
                <label>连接世界书进行优化</label>
                <label class="toggle-switch">
                   <input id="amily2_worldbook_enabled" type="checkbox">
                   <span class="slider"></span>
                </label>
               <small class="notes">独立开关：决定优化时是否读取世界书内容作为参考。</small>
           </div>
           <div class="amily2_settings_block">
               <label>总结写入目标:</label>
               <div class="radio-group">
                   <input type="radio" id="amily2_target_main" name="amily2_lorebook_target" value="character_main" checked>
                   <label for="amily2_target_main">写入【主世界书】</label>
                   <input type="radio" id="amily2_target_dedicated" name="amily2_lorebook_target" value="dedicated">
                   <label for="amily2_target_dedicated">写入【独立档案】</label>
               </div>
               <small class="notes">此设置仅在“启用即时总结”开启时生效。</small>
           </div>
        </div>

        <div class="amily2_vertical_divider"></div>

        <div class="amily2_lore_config_section">
            <div class="amily2_settings_block">
                <label for="amily2_lore_activation_mode">默认激活模式:</label>
                <select id="amily2_lore_activation_mode" class="text_pole">
                    <option value="always">🔵 蓝灯 (始终激活)</option>
                    <option value="keyed">🟢 绿灯 (关键词触发)</option>
                </select>
            </div>
            <div class="amily2_settings_block">
                <label for="amily2_lore_insertion_position">默认插入位置:</label>
                <select id="amily2_lore_insertion_position" class="text_pole">
                    <option value="before_char">角色定义之前</option>
                    <option value="after_char">角色定义之后</option>
                    <option value="before_an">作者注释之前</option>
                    <option value="after_an">作者注释之后</option>
                    <option value="at_depth">@D 注入指定深度</option>
                </select>
            </div>
            <div id="amily2_lore_depth_container" class="amily2_settings_block" style="display: none;">
                <label for="amily2_lore_depth_input">注入深度:</label>
                <input id="amily2_lore_depth_input" title="深度" class="text_pole wideMax100px margin0" type="number" name="depth" placeholder="2" min="0" max="9999" style="width: calc(3em + 25px);">
            </div>
            <div class="amily2_settings_block" style="margin-top: auto;">
                <button id="amily2_save_lore_settings" class="menu_button"><i class="fas fa-save"></i> 确认敕令</button>
                <small id="amily2_lore_save_status" class="notes" style="text-align: center; width: 100%;"></small>
            </div>
        </div>

    </div>
</fieldset>

			 
			<fieldset class="settings-group">
                <legend><i class="fas fa-palette"></i> 界面定制</legend>
                <div class="amily2_settings_block">
                    <label>帝国徽记位置:</label>
                    <div class="radio-toggle-group">
                        <input type="radio" id="amily2_icon_location_topbar" name="amily2_icon_location" value="topbar">
                        <label for="amily2_icon_location_topbar">驻扎顶栏</label>
                        <input type="radio" id="amily2_icon_location_extensions" name="amily2_icon_location" value="extensions">
                        <label for="amily2_icon_location_extensions">收归扩展</label>
                    </div>
                    <small class="notes">为解决部分移动端UI溢出问题。更改后将立即生效。</small>
                </div>
                <div class="amily2_settings_block color-controls-container">
                    <div class="color-picker-group">
                        <div class="color-picker-item">
                            <label for="amily2_bg_color">背景色:</label>
                            <input type="color" id="amily2_bg_color" value="#1e1e1e">
                        </div>
                        <div class="color-picker-item">
                            <label for="amily2_button_color">按钮色:</label>
                            <input type="color" id="amily2_button_color" value="#4a4a4a">
                        </div>
                        <div class="color-picker-item">
                            <label for="amily2_text_color">文字颜色:</label>
                            <input type="color" id="amily2_text_color" value="#ffffff">
                        </div>
                    </div>
                    <button id="amily2_restore_colors" class="menu_button small_button">默认</button>
                </div>
                <div class="amily2_settings_block">
                    <label for="amily2_bg_opacity">背景透明度: <span id="amily2_bg_opacity_value">0</span></label>
                    <input type="range" id="amily2_bg_opacity" min="0" max="1" step="0.01" value="0">
                </div>
                <div class="amily2_settings_block">
                    <label>自定义背景图:</label>
                    <div style="display: flex; gap: 10px; align-items: center;">
                        <label for="amily2_custom_bg_image" class="menu_button wide_button" style="cursor: pointer; text-align: center; flex-grow: 1;">
                            <i class="fas fa-upload"></i> 上传图片
                        </label>
                        <input type="file" id="amily2_custom_bg_image" accept="image/*" style="display: none;">
                        <button id="amily2_restore_bg_image" class="menu_button small_button">默认</button>
                    </div>
                    <small class="notes">选择一张图片作为背景。推荐使用小于5MB的图片。</small>
                </div>
            </fieldset>
			
                <legend><i class="fas fa-tools"></i> 诊断与操作</legend>
                <div class="amily2_settings_block button-pair">
                    <button class="menu_button primary interactable" id="amily2_test"><i class="fas fa-search"></i> 测试检查</button>
                    <button class="menu_button accent interactable" id="amily2_fix_now"><i class="fas fa-magic"></i> 立即修复</button>
                </div>
            </fieldset>
        </div>

        <div id="amily2_hidden_prompts" style="display:none;">
            <div class="amily2_settings_block">
                <div class="prompt-container">
                    <textarea id="amily2_main_prompt" class="text_pole" rows="6"></textarea>
                    <button id="save_main_prompt" class="menu_button small_button interactable"><i class="fas fa-save"></i> 保存</button>
                </div>
            </div>
            <div class="amily2_settings_block">
                <div class="prompt-container">
                    <textarea id="amily2_system_prompt" class="text_pole" rows="8"></textarea>
                    <button id="save_system_prompt" class="menu_button small_button interactable"><i class="fas fa-save"></i> 保存</button>
                </div>
            </div>
            <div class="amily2_settings_block">
                <div class="prompt-container">
                    <textarea id="amily2_output_format_prompt" class="text_pole" rows="4"></textarea>
                    <button id="save_output_format_prompt" class="menu_button small_button interactable"><i class="fas fa-save"></i> 保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

